package client.net;

/*
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 * TcpPacketHandler.java
 *
 * Steven Louie Apr. 8, 2012
 */
import client.ActinoClient;
import client.models.ActinoPlayer;
import com.esotericsoftware.kryonet.Client;

public class TcpPacketHandler {

    private Client client;
    
    public TcpPacketHandler(Client client) {
        this.client = client;
    }

    public void sendChatMessage(String s) {
        ChatMessage msg = new ChatMessage();
        msg.type = ChatMessage.Type.LOCAL;
        msg.source = ActinoClient.getInstance().getPlayer().name;
        msg.text = s;
        client.sendTCP(msg);
    }
    
    public void sendMovement(ActinoPlayer p) {
        MovementAction mvt = new MovementAction();
        mvt.name = p.name;
        mvt.imgName = p.imgName;
        mvt.imgIndex = p.currentImageIndex;
        mvt.dir = p.dir;
        mvt.x = p.x;
        mvt.y = p.y;
        mvt.px = p.px;
        mvt.py = p.py;
        client.sendTCP(mvt);
    }
    
    public void sendLogin(String username, String password) {
        LoginAction login = new LoginAction();
        login.username = username;
        login.password = password;
        client.sendTCP(login);
    }
    
    public void sendNPCTest(String npc) {
        NPCInteraction action = new NPCInteraction();
        action.type = "next";
        action.npc = Integer.parseInt(npc);
        client.sendTCP(action);
    }
}
